
public class hormiga {
	
	int x;
	int y;

	
	//1 mira al norte 
	//2 mira al este
	//3 mira al sur 
	//4 mira al oeste 
	int orientacion; 
	
	int [][] matriz = 
			{{3,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0},
			 {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0},
			 {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0},
			 {0,0,0,1,1,1,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0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,0,0,0,0,0},
			 {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
			};
	//0 si no hay nada
	//1 si hay comida
	//2 si ha estado la hormiga
	//3 si ha estado la hormiga y habia comida
	
	//asi luego la puntuacion sera contar el numero de 3 de la matriz


public hormiga (){
	
	//supongo que la esquina superior izquierda es el 0 0
	x= 0;
	y= 0;
	
	//inicialmente mira al este
	orientacion=2;
	
	//inicializar matriz
	
}


public void mueveHormiga (int movimiento) {

boolean avanza= false;  //variable para saber si ha avanzado

//movimiento 0: gira izquierda;
//movimiento 1: gira derecha;
//movimiento 2: avanza

if (movimiento == 0){
	
	switch (this.orientacion){
	case 1: orientacion=4; break;
	case 2: orientacion=1;break;
	case 3: orientacion=2;break;
	case 4: orientacion=3;break;
	}
	
} else if (movimiento == 1){
		
		switch (this.orientacion){
		case 1: orientacion=2; break;
		case 2: orientacion=3;break;
		case 3: orientacion=4;break;
		case 4: orientacion=1;break;
		}
}
else if (movimiento==2){
	
	avanza = true;
	
	switch (this.orientacion){
	//avanza al norte
	case 1: x=x-1; if (x==-1) x = matriz.length-1;break;
	//avanza al este
	case 2: y=y+1;if (y==matriz.length) y=0;break;
	//avanza al sur
	case 3: x=x+1; if (x==matriz.length) x=0; break;
	//avanza al oeste
	case 4: y=y-1; if (y==-1) y = matriz.length-1;  break;
	
	}
}

//if para modificar la matriz
if (avanza){
	
	switch (matriz[x][y]){
	//si no habia nada ahora hay hormiga
	case 0: matriz[x][y]=2;break;
	//si habia comida ahora hay comida y hormiga
	case 1: matriz[x][y]=3;break;
	//si la hormiga habia estado ahi, queda igual
	case 2: matriz[x][y]=2;break;
	//si la hormiga habia estado ahi y habia comido, queda igual
	case 3:	matriz[x][y]=3;break; 
	}
	
	
	
}

}
//FUNCION QUE MIRA SI LA HORMIGA TIENE COMIDA DELANTE
public boolean comidaDelante () {
	boolean encontrado = false;
	int posMira=0;
	
	switch (orientacion){

	//mirando al norte
	case 1: {
		if (x==0) 
			posMira = matriz.length-1;
		else
			posMira = x-1;
		
		if (matriz[posMira][y]==1) encontrado=true;
	}
	break;
	case 2: {
		if (y==matriz.length-1) 
			posMira = 0;
		else
			posMira = y+1;
		
		if (matriz[x][posMira]==1) encontrado=true;
	}
	break;
	case 3: {
		if (x==matriz.length-1) 
			posMira = 0;
		else
			posMira = x+1;
		
		if (matriz[posMira][y]==1) encontrado=true;
	}
	break;
	case 4: {
		if (y==0) 
			posMira = 0;
		else
			posMira = y-1;
		
		if (matriz[x][posMira]==1) encontrado=true;
	}
	break;
	}
	
	
	return encontrado;
}
	
}
	
